﻿// Copyright 2010 Maxime Serrano <lastchronicler@gmail.com>
using System;
using System.IO;

namespace ForgeCraft.Network.Handlers
{
    class BlockDigHandler : PacketHandler
    {
        #region PacketHandler Members

        public void Handle(BinaryReader reader, Session session, Player player)
        {
            byte status = reader.ReadByte();
            int blockX = PacketWriter.SwapEndian(reader.ReadUInt32());
            byte blockY = reader.ReadByte();
            int blockZ = PacketWriter.SwapEndian(reader.ReadUInt32());
            /* byte dir = */
            reader.ReadByte();

            // Permission check
            if (!player.info.group.canDelete)
            {
                if (DateTime.UtcNow.Subtract(player.lastWarned).Seconds > 2)
                {
                    player.Message(Color.Red + "You are not allowed to delete blocks!");
                    player.lastWarned = DateTime.UtcNow;
                }
                return;
            }

            // Destroy block (if broken or in Instant Break mode)
            if (status == 2 || player.InstantBreak)
            {
                player.DestroyBlock(blockX, blockY, blockZ);
            }
        }

        #endregion
    }

    public class BlockPlaceHandler : PacketHandler
    {

        #region PacketHandler Members

        public void Handle(BinaryReader reader, Session session, Player player)
        {
            /*// Read in data
            short type = PacketWriter.SwapEndian(reader.ReadInt16());
            int blockX = PacketWriter.SwapEndian(reader.ReadUInt32());
            byte blockY = reader.ReadByte();
            int blockZ = PacketWriter.SwapEndian(reader.ReadUInt32());
            byte dir = reader.ReadByte();

            // Permission check
            if (!player.info.group.canBuild)
            {
                if (DateTime.UtcNow.Subtract(player.lastWarned).Seconds > 2)
                {
                    player.Message(Color.Red + "You are not allowed to place blocks!");
                    player.lastWarned = DateTime.UtcNow;
                }
                return;
            }

            // Place block
            player.PlaceBlock((byte)type, blockX, blockY, blockZ, dir);*/
        }

        #endregion
    }
}
